﻿//Encapsulates data calls to server (AJAX calls) using Closure 

var dataService = new function () {
    var serviceBase = '/JSONData/',
        //getAccount = function(login, callback) {
    //    $.getJSON(serviceBase + 'GetPlayer', { login: login }, function(data) {
    //        callback(data);
    //    });
    //},
        
        getAccountFull = function(login, callback) {
            $.getJSON(serviceBase + 'GetPlayerFull', { login: login }, function(data) {
                callback(data);
            });
        },
        getNewGame = function(login, callback) {
            $.getJSON(serviceBase + 'GetNewGame', { login: login }, function(data) {
                callback(data);
            });
        },
        getBestPlayers = function (login, callback) {
            $.getJSON(serviceBase + 'GetBestPlayers', { login: login }, function (data) {
                callback(data);
            });
        },
        getStatistics = function (login, callback) {
            $.getJSON(serviceBase + 'GetStatistics', { login: login }, function (data) {
                callback(data);
            });
        },
        getLastGame = function (login, callback) {
            $.getJSON(serviceBase + 'GetLastGame', { login: login }, function (data) {
                callback(data);
            });
        },
        saveNewGame = function(grayDefence, grayAttack, blackDefence, blackAttack, grayPoints, balckPoints, login, level, callback) {
            $.getJSON(serviceBase + 'SaveNewGame',
                { grayDefence: grayDefence, grayAttack: grayAttack, blackDefence: blackDefence, blackAttack: blackAttack, grayPoints: grayPoints, balckPoints: balckPoints, login: login, level: level },
                function(data) {
                    callback(data);
                });
        };

    //postJSON = function (url, data, func) {
    //    $.post(url + (url.indexOf("?") == -1 ? "?" : "&") + "callback=?", data, func, "json");
    //};

    return {
        //getAccount: getAccount,
        getAccountFull: getAccountFull,
        getNewGame: getNewGame,
        getBestPlayers: getBestPlayers,
        saveNewGame: saveNewGame,
        getLastGame: getLastGame,
        getStatistics: getStatistics,
    };

} ();